package com.dongdongshop.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.ContentCategoryService;
import com.dongdongshop.util.PageBean;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class ContentCategoryServiceImpl implements ContentCategoryService {
    @Resource
    private TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public List<TbContentCategory> getinfo() {
        return tbContentCategoryMapper.selectByExample(null);
    }

    @Override
    @Transactional
    public PageBean<TbContentCategory> getAll(Integer number, Integer pageSize, String sname) {
        PageBean<TbContentCategory> b = new PageBean<>();
        b.setPageNum(number);
        b.setPageSize(pageSize);
        List<TbContentCategory> list = tbContentCategoryMapper.getAll(b,sname);
        List<TbContentCategory> slist = tbContentCategoryMapper.getCount(sname);
        b.setResult(list);
        b.setTotal(slist.size());
        return b;
    }

    @Override
    public Integer addinfo(TbContentCategory tbContentCategory) {
        return tbContentCategoryMapper.insertSelective(tbContentCategory);
    }

    @Override
    public Integer deleteAll(Long[] ids) {
        return tbContentCategoryMapper.deleteAll(ids);
    }

    @Override
    public TbContentCategory toUpdate(Long id) {
        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updateinfo(TbContentCategory tbContentCategory) {
        return tbContentCategoryMapper.updateByPrimaryKeySelective(tbContentCategory);
    }
}
